home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Performance: C vs. C++
- Date: 14 Jan 1996 10:43:18 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4damo6$338@news1.usa.pipeline.com>
- References: <4da9pn$a45@news.bridge.net>
- NNTP-Posting-Host: pipe8.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Jan 14, 1996 07:02:15 in article <Re: Performance: C vs. C++>, 'David
- Byrden <100101.2547@compuserve.com>' wrote:
-
-
- >
- >Steve;
- >
- >C and C++ are so similar that I would expect similar code to produce
- >almost identical performance. However, note that while virtual functions
- >cause overhead when you use them, exceptions in most present compilers can
-
- >cause overhead *at every function call*.
- >
- Looking at .asm output of source code compiled with MSVC++4.0 revealed
- that the cost of exception is only in the routines actually containing
- exception code. The following points consider the cost only if an
- exception is not thrown. I don't think we really care how much extra
- is involved when an exception acctually occurs.
-
- I you have try - catch blocks in your code and call a function
- from within as well as outside the try block, there's an extra push
- instruction in invoking the call and an extra add-esp upon return
- involved in the call inside the try.
-
- The 'setup' for the try block itself is appears to be not much. I need
- to do some more experimenting to find out just how many extra
- instructions are involved. Right now I'll say it's peanuts. Inside
- the try block is an extra push and one extra jump (to bypass the
- catch blocks). There appears to be some exception related
- instructions in a section some distance from the try-catch blocks.
-
- If you have a throw in a function, then there are six extra instructions
- upon entry to the function, but none on exit. The extras are three
- push, two mov and one sub. (Not counting the code to test
- whether or not an exception should be thrown.)
-
- So, the bottom line: The cost is definitely there where the exception
- code exists, but in code that is not involved, there's none. Don't
- forget that this investigation was performed only on one compiler
- in one environment (Win95) and may produce similar results
- elsewhere.
-
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-